import {
  createNamespacedHelpers
} from 'vuex'
const {
  mapGetters,
  mapActions
} = createNamespacedHelpers('player')
// 迷你播放器
export const playMiniMixin = {
  computed: {
    ...mapGetters([
      'currentSong', 'contentBottom'
    ])
  },
  watch: {
    currentSong(news, old) {
      if (news) {
        this.$nextTick(() => {
          this.refresh()
        })
      } else {}
    }
  },
  methods: {
    ...mapActions(['openP', 'next'])
  }
}
// 播放器
export const playerMixin = {
  computed: {
    ...mapGetters([
      'currentSong'
    ])
  },
  methods: {
    ...mapActions(['openP', 'next'])
  }
}

// 搜索历史模块
export const localMixin = {
  methods: {
    // eg: 余数,阿斯顿撒
    setLocalStorage(key, value) {
      var prev = localStorage.getItem(key)
      if (prev) {
        var arr = prev.split(',')
        // 去重
        var i = arr.indexOf(value)
        if (i !== -1) {
          arr.splice(i, 1)
        }
        arr.unshift(value)
        localStorage.setItem(key, arr.join(','))
      } else {
        localStorage.setItem(key, value)
      }
    },
    getLocalStorage(key) {
      var prev = localStorage.getItem(key)
      if (prev) {
        return prev.split(',')
      } else {
        return []
      }
    }
  }
}
